using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Web.SessionState;

namespace KenLib.Common
{
    public class csCommon
    {
        public static string Export(HtmlForm Form, List<int> lsID, List<Object> ls, string[] name, string[] url)
        {
            //= (List<Object>)sess["NyukokuJouhouSakusei"];
            //List<int>lsID=new List<int>();
            //lsID.Add(Convert.ToInt32(ls[4].ToString()));
            //Session["ID"] = lsID;
            StringBuilder script = new StringBuilder();
            script.Append("<script>");
            for (int i = 0; i < name.Length; i++)
            {
                if (name[i].IndexOf("chk_") != -1)
                {
                    CheckBox chkTemp = (CheckBox)Form.FindControl(name[i]);
                    if (chkTemp != null && chkTemp.Checked)
                    {
                        if (name[i] == "chk_10_1")
                        {
                            //= (List<int>)Session["ID"];
                            for (int j = 0; j < lsID.Count; j++)
                            {
                                script.Append("window.open('" + url[i] + "?id1=" + ls[0].ToString() + "&id2=" + ls[2].ToString() + "&id3=" + ls[4].ToString() + "&id4=" + lsID[j].ToString() + "');");
                            }
                        }
                        else if (name[i] == "chk_10_10_3" || name[i] == "chk_10_20" || name[i] == "chk_10_29" || name[i] == "chk_10_22")
                        {
                            string[] strKKs = ls[6].ToString().Replace("_", "").Split(',');
                            for (int j = 0; j < strKKs.Length; j++)
                            {
                                script.Append("window.open('" + url[i] + "?id1=" + ls[0].ToString() + "&id2=" + ls[2].ToString() + "&id3=" + ls[4].ToString() + "&id4=" + strKKs[j] + "');");
                            }
                        }
                        else if (name[i] == "chk_10_13" || name[i] == "chk_10_39")
                        {
                            script.Append("window.open('" + url[i] + "?id1=" + ls[0].ToString() + "&id2=" + ls[2].ToString() + "&id3=" + ls[4].ToString() + "&id4=" + ls[6].ToString().Replace("_", "") + "');");
                        }
                        else
                            script.Append("window.open('" + url[i] + "?id1=" + ls[0].ToString() + "&id2=" + ls[2].ToString() + "&id3=" + ls[4].ToString() + "');");
                    }
                }
            }
            script.Append("</script>");
            if (!script.ToString().Equals("<script></script>"))
            {
                return script.ToString();
            }
            else return "";
        }
    }
}
